package com.starhub.common.exception;

import com.starhub.common.enumeration.ResultCodeEnum;
import com.starhub.utils.Util;

public class AppException extends RuntimeException {
    private static final long serialVersionUID = 4417232441543827397L;
    private int code;
    private String message;


    public AppException() {
        this.code = ResultCodeEnum.SUCCESS.getCode();
    }

    public AppException(Throwable e) {
        super(e);
        this.code = ResultCodeEnum.SUCCESS.getCode();
    }

    public AppException(int code) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.code = code;
    }

    public AppException(Throwable e, int code) {
        super(e);
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.code = code;
    }

    public AppException(String message) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.message = message;
    }

    public AppException(Throwable e, String message) {
        super(e);
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.message = message;
    }

    public AppException(int code, String message) {
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.code = code;
        this.message = message;
    }

    public AppException(Throwable e, int code, String message) {
        super(e);
        this.code = code;
        this.message = message;
    }


    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        if (Util.isEmpty(this.message)) {
            this.message = super.getMessage();
        }

        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}